package com.example.demo.controller;

import com.example.demo.entity.Book_instrument;
import com.example.demo.entity.User;
import com.example.demo.service.Book_instrumentService;
import com.example.demo.service.StudentService;
import com.example.demo.service.impl.StudentImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller

//@RequestMapping(value="/login")
public class LoginController {
    @Autowired
    StudentService studentService;
    @Autowired
    Book_instrumentService book_instrumentService;

    @GetMapping(value={"/","/login"})
    public String loginPage(){
        return "login";
    }

    @PostMapping(value="/login")
    public String dealLogin(User user, HttpSession session, Model model){
//        studentService=new StudentImpl();

        String id = user.getId();
        String password=user.getPassword();

        if(password.equals(studentService.queryPasswordById(id))){
            session.setAttribute("loginuser",user);
            return "redirect:/index.html";
        }else{
            model.addAttribute("msg","wrong username or password!");
            return "login";
        }
    }

}
